package cn.study.controller;
import cn.study.entity.StudyTestPaper;
import cn.study.entity.StudyTestPaperParticulars;
import cn.study.service.StudyTestPaperParticularsService;
import cn.study.service.StudyTestPaperService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 试卷表 前端控制器
 * </p>
 *
 * @author qiao
 * @since 2020-06-22
 */
@Controller
@Slf4j
@RequestMapping("/study-test-paper")
public class StudyTestPaperController {
    @Resource
    StudyTestPaperService studyService;
    @Autowired
    StudyTestPaperParticularsService studyTestPaperParticularsService;
    @Autowired
    StudyTestPaperService studyTestPaperService;
    @GetMapping("/shijuanlist")
    public String list(Model model, @RequestParam(value="pn",defaultValue="1") Integer pn,
                       @RequestParam(value="paginalsize",defaultValue = "5") Integer paginalsize) {
        PageHelper.startPage(pn, paginalsize);
        List<StudyTestPaperParticulars> list = studyService.getlist();
        PageInfo pInfo = new PageInfo(list, 10);
        model.addAttribute("pInfo", pInfo);
        model.addAttribute("paginalsize", paginalsize);
        return "study_shijuanlist";
    }
    @GetMapping("/shijuanlistaaa")
    public String list(Model model,  @RequestParam(value="pageid",defaultValue="1") Integer pageid) {
        List<StudyTestPaper> list1 = studyService.getlistid();
        model.addAttribute("pagelist", list1);
        List<StudyTestPaperParticulars> list = studyService.getlistaaa(pageid);
        model.addAttribute("pInfo", list);

        return "study_shijuanlist";
    }
    @GetMapping("/add")
    public String add()
    {

        return "study_shijuan_add";
    }

    @PostMapping("/deptadd")
    public String deptadd(StudyTestPaper department){
        boolean bl=studyService.save(department);
        if(bl){
            log.info("添加成功");
        }else {
            log.info("添加失败");
        }
        return "redirect:/study-shijuanlist/list";
    }


    @GetMapping("del")
    public String del(Integer id)
    {
        boolean bl=studyService.removeById(id);
        if(bl){
            log.info("删除成功");
        }else {
            log.info("删除失败");
        }
        return "redirect:/study-shijuanlist/list";
    }
    @GetMapping("/upd")
    public String upd(Integer id,Model model)
    {
        StudyTestPaper studyDepartment=studyService.getById(id);
        model.addAttribute("list",studyDepartment);
        return "study_shijuan_upd";
    }

    @PostMapping("/deptupd")
    public String deptupd(Model model,StudyTestPaper department)
    {
        studyService.updateById(department);
        return "redirect:/study-shijuanlist/list";
    }

}

